package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Classroom;
import cn.wolfcode.crm.domain.Grade;
import cn.wolfcode.crm.query.ClassQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IClassroomService;
import cn.wolfcode.crm.service.IGradeService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("classroom")
public class ClassroomController {

    @Autowired
    private IClassroomService classroomService;


    @RequestMapping("list")
    @ResponseBody
    public List<Classroom> list() {
        return classroomService.selectAll();
    }

    @RequestMapping("view")
    public String query(QueryObject qo) {
        return "classroom";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Classroom classroom) {
        JSONResult result = new JSONResult();
        try {
            classroomService.saveOrUpdate(classroom);
        } catch (Exception e) {
            result.remark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

  
    @RequestMapping("query")
    @ResponseBody
    public PageResult classroom(ClassQueryObject qo) {
        return classroomService.query(qo);
    }

    @RequestMapping("validateName")
    @ResponseBody
    public Boolean validateName(String name, Long id) {
        return classroomService.validateName(name, id);
    }

    @RequestMapping("changeState")
    @ResponseBody
    public JSONResult changeState(Long id) {
        JSONResult result = new JSONResult();
        try {
            classroomService.changeState(id);
        } catch (Exception e) {
            result.remark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }
   
}
